home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / program / misc / bgui12.lha / demos / MultiSelect.c < prev    next >
C/C++ Source or Header  |  1995-05-19  |  10KB  |  195 lines

  1. ;/* Execute me to compile with DICE V3.0
  2. dcc multiselect.c -proto -mi -ms -mRR -lbgui
  3. quit
  4. */
  5. /*
  6.  *      MULTISELECT.C
  7.  *
  8.  *      (C) Copyright 1995 Jaba Development.
  9.  *      (C) Copyright 1995 Jan van den Baard.
  10.  *          All Rights Reserved.
  11.  */
  12.  
  13. #include "democode.h"
  14.  
  15. /*
  16. **      The entries shown in the list.
  17. **/
  18. UBYTE   *ListEntries[] = {
  19.         ISEQ_C "This listview object has multi-",
  20.         ISEQ_C "selection turned on. You can",
  21.         ISEQ_C "multi-select the items by holding",
  22.         ISEQ_C "down the SHIFT-key while clicking",
  23.         ISEQ_C "on the different items or by clicking",
  24.         ISEQ_C "on an entry and dragging the mouse",
  25.         ISEQ_C "up or down.",
  26.         "",
  27.         ISEQ_C "If you check the \"No SHIFT\" checbox",
  28.         ISEQ_C "you can multi-select the items without",
  29.         ISEQ_C "using the SHIFT key",
  30.         NULL
  31. };
  32.  
  33. /*
  34. **      Map-list.
  35. **/
  36. struct TagItem CheckToList[] = { GA_Selected, LISTV_MultiSelectNoShift, TAG_END };
  37.  
  38. /*
  39. **      Object ID's.
  40. **/
  41. #define ID_SHOW                 1
  42. #define ID_QUIT                 2
  43. #define ID_ALL                  3
  44. #define ID_NONE                 4
  45.  
  46. VOID StartDemo( void )
  47. {
  48.         struct Window           *window;
  49.         Object                  *WO_Window, *GO_Quit, *GO_Show, *GO_List, *GO_Shift, *GO_All, *GO_None;
  50.         ULONG                    signal, rc, tmp = 0;
  51.         BOOL                     running = TRUE;
  52.  
  53.         /*
  54.          *      Create the window object.
  55.          */
  56.         WO_Window = WindowObject,
  57.                 WINDOW_Title,           "Multi-Selection Demo",
  58.                 WINDOW_AutoAspect,      TRUE,
  59.                 WINDOW_SmartRefresh,    TRUE,
  60.                 WINDOW_RMBTrap,         TRUE,
  61.                 WINDOW_ScaleWidth,      30,
  62.                 WINDOW_ScaleHeight,     30,
  63.                 WINDOW_MasterGroup,
  64.                         VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), GROUP_BackFill, SHINE_RASTER,
  65.                                 StartMember,
  66.                                         VGroupObject, HOffset( 4 ), VOffset( 4 ),
  67.                                                 FRM_Type,               FRTYPE_BUTTON,
  68.                                                 FRM_Recessed,           TRUE,
  69.                                                 StartMember,
  70.                                                         GO_List = ListviewObject,
  71.                                                                 LISTV_EntryArray,               ListEntries,
  72.                                                                 LISTV_MultiSelect,              TRUE,
  73.                                                         EndObject,
  74.                                                 EndMember,
  75.                                                 StartMember,
  76.                                                         HGroupObject,
  77.                                                                 StartMember, GO_All  = KeyButton( "_All",  ID_ALL  ), EndMember,
  78.                                                                 StartMember, GO_None = KeyButton( "N_one", ID_NONE ), EndMember,
  79.                                                         EndObject, FixMinHeight,
  80.                                                 EndMember,
  81.                                         EndObject,
  82.                                 EndMember,
  83.                                 StartMember,
  84.                                         HGroupObject, HOffset( 4 ), VOffset( 4 ),
  85.                                                 FRM_Type,               FRTYPE_BUTTON,
  86.                                                 FRM_Recessed,           TRUE,
  87.                                                 VarSpace( DEFAULT_WEIGHT ),
  88.                                                 StartMember, GO_Shift = KeyCheckBox( "_No SHIFT:", FALSE, 0 ), EndMember,
  89.                                                 VarSpace( DEFAULT_WEIGHT ),
  90.                                         EndObject, FixMinHeight,
  91.                                 EndMember,
  92.                                 StartMember,
  93.                                         HGroupObject, Spacing( 4 ),
  94.                                                 StartMember, GO_Show = KeyButton( "_Show", ID_SHOW ), EndMember,
  95.                                                 VarSpace( DEFAULT_WEIGHT ),
  96.                                                 StartMember, GO_Quit = KeyButton( "_Quit", ID_QUIT ), EndMember,
  97.                                         EndObject, FixMinHeight,
  98.                                 EndMember,
  99.                         EndObject,
  100.         EndObject;
  101.  
  102.         /*
  103.         **      Object created OK?
  104.         **/
  105.         if ( WO_Window ) {
  106.                 /*
  107.                 **      Assign the keys to the buttons.
  108.                 **/
  109.                 tmp += GadgetKey( WO_Window, GO_Quit,  "q" );
  110.                 tmp += GadgetKey( WO_Window, GO_Show,  "s" );
  111.                 tmp += GadgetKey( WO_Window, GO_Shift, "n" );
  112.                 tmp += GadgetKey( WO_Window, GO_All,   "a" );
  113.                 tmp += GadgetKey( WO_Window, GO_None,  "o" );
  114.                 /*
  115.                 **      OK?
  116.                 **/
  117.                 if ( tmp == 5 ) {
  118.                         /*
  119.                         **      Add notification.
  120.                         **/
  121.                         if ( AddMap( GO_Shift, GO_List, CheckToList )) {
  122.                                 /*
  123.                                 **      try to open the window.
  124.                                 **/
  125.                                 if ( window = WindowOpen( WO_Window )) {
  126.                                         /*
  127.                                         **      Obtain it's wait mask.
  128.                                         **/
  129.                                         GetAttr( WINDOW_SigMask, WO_Window, &signal );
  130.                                         /*
  131.                                         **      Event loop...
  132.                                         **/
  133.                                         do {
  134.                                                 Wait( signal );
  135.                                                 /*
  136.                                                 **      Handle events.
  137.                                                 **/
  138.                                                 while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  139.                                                         /*
  140.                                                         **      Evaluate return code.
  141.                                                         **/
  142.                                                         switch ( rc ) {
  143.  
  144.                                                                 case    WMHI_CLOSEWINDOW:
  145.                                                                 case    ID_QUIT:
  146.                                                                         running = FALSE;
  147.                                                                         break;
  148.  
  149.                                                                 case    ID_ALL:
  150.                                                                         SetGadgetAttrs(( struct Gadget * )GO_List, window, NULL, LISTV_SelectMulti, LISTV_Select_All, TAG_END );
  151.                                                                         break;
  152.  
  153.                                                                 case    ID_NONE:
  154.                                                                         SetGadgetAttrs(( struct Gadget * )GO_List, window, NULL, LISTV_DeSelect, ~0, TAG_END );
  155.                                                                         break;
  156.  
  157.                                                                 case    ID_SHOW:
  158.                                                                         UBYTE           *str;
  159.  
  160.                                                                         /*
  161.                                                                         **      Simply dump all selected entries
  162.                                                                         **      to the console.
  163.                                                                         **/
  164.                                                                         if ( str = ( UBYTE * )FirstSelected( GO_List )) {
  165.                                                                                 do {
  166.                                                                                         Tell( "%s\n", str + 2 );
  167.                                                                                         str = ( UBYTE * )NextSelected( GO_List, str );
  168.                                                                                 } while ( str );
  169.                                                                         } else
  170.                                                                                 /*
  171.                                                                                 **      Oops. There are no selected
  172.                                                                                 **      entries.
  173.                                                                                 **/
  174.                                                                                 Tell( "No selections made!\n" );
  175.                                                                         break;
  176.                                                         }
  177.                                                 }
  178.                                         } while ( running );
  179.                                 } else
  180.                                         Tell( "Could not open the window\n" );
  181.                         } else
  182.                                 Tell( "Unable to add notification\n" );
  183.                 } else
  184.                         Tell( "Could not assign gadget keys\n" );
  185.                 /*
  186.                 **      Disposing of the window object will
  187.                 **      also close the window if it is
  188.                 **      already opened and it will dispose of
  189.                 **      all objects attached to it.
  190.                 **/
  191.                 DisposeObject( WO_Window );
  192.         } else
  193.                 Tell( "Could not create the window object\n" );
  194. }
  195.